﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////

// Reviewed

#pragma once

#include "GcmpGeometryInterface.h"

namespace gcmp
{
    class Vector2d;
    class Vector3d;
    class IFace;
    class ICurve3d;
    class ILine3d;
    class IPlane;
    class IArc3d;
    class ICurve2d;
    class ISurface;
    class IBody;

    class IDistance
    {
    public:
        virtual ~IDistance() {}

        /// \brief  计算两条三维曲线间的最小距离
        /// \param const ICurve3d* pFirGmICurve3d    第一条三维曲线
        /// \param const ICurve3d* pSecGmICurve3d    第二条三维曲线
        /// \param Vector3d &minDisPtOnCurve1         第一条曲线上的最小距离点
        /// \param Vector3d &minDisPtOnCurve2         第二条曲线上的最小距离点
        /// \param minimalDistance                    最小距离
        /// \return    true:成功； false:失败
        virtual bool Calculate(const ICurve3d* pFirGmICurve3d, const ICurve3d* pSecGmICurve3d, Vector3d &minDisPtOnCurve1, Vector3d &minDisPtOnCurve2, double& minimalDistance)const = 0;

        /// \brief  计算空间点到三维曲线间的最小距离
        /// \param const ICurve3d* pGmICurve3d       三维曲线
        /// \param const Vector3d& queryPoint        空间点
        /// \param Vector3d& minDisPtOnCurve         三维曲线上的最小距离点
        /// \param bool bLimit                       曲线是否有限长
        /// \param double* const pParamOnCurve       最小距离点在曲线上的参数(指针输入为空时不输出)
        /// \param minimalDistance                   最小距离
        /// \return    true:成功； false:失败
        virtual bool Calculate(const ICurve3d* pGmICurve3d, const Vector3d& queryPoint, Vector3d& minDisPtOnCurve, bool bLimit, double* const pParamOnCurve, double& minimalDistance)const = 0;

        /// \brief  计算二维曲线到二维曲线间的最小距离
        /// \param const ICurve2d* pGmICurve2d1        二维曲线
        /// \param const ICurve2d *pGmICurve2d2        二维曲线
        /// \param Vector2d &minDisPtOnCurve1           二维曲线1上的最小距离点
        /// \param Vector2d &minDisPtOnCurve2           二维曲线2上的最小距离点
        /// \param minimalDistance                   最小距离
        /// \return    true:成功； false:失败
        virtual bool Calculate(const ICurve2d *pGmICurve2d1, const ICurve2d *pGmICurve2d2, Vector2d &minDisPtOnCurve1, Vector2d &minDisPtOnCurve2, double& minimalDistance)const = 0;

        /// \brief  计算二维点到二维曲线间的最小距离
        /// \param const ICurve2d* pGmICurve2d        二维曲线
        /// \param const Vector2d& queryPoint           二维点
        /// \param Vector2d &minDisPtOnCurve           二维曲线上的最小距离点
        /// \param bool bLimit                          曲线是否有限长
        /// \param double* const pParamOnCurve     最小距离点在二维曲线上的参数(指针输入为空时不输出)
        /// \param minimalDistance                   最小距离
        /// \return    true:成功； false:失败
        virtual bool Calculate(const ICurve2d* pGmICurve2d, const Vector2d& queryPoint, Vector2d &minDisPtOnCurve, bool bLimit, double* const pParamOnCurve, double& minimalDistance)const = 0;

        /// \brief  计算空间点到曲面的最小距离
        /// \param const ISurface* pGmISurface              曲面
        /// \param const Vector3d& queryPoint               三维点
        /// \param Vector3d &minDisPtOnPlane                曲面上的最小距离点
        /// \param bool bLimit                              平面范围是否有限
        /// \param Vector2d* const pParamOnSurface          最小距离点在曲面上的参数(指针输入为空时不输出)
        /// \param minimalDistance                          最小距离
        /// \param double disTolerance                      距离容差
        /// \return    true:成功； false:失败
        virtual bool Calculate(const ISurface* pGmISurface, const Vector3d& queryPoint, Vector3d &minDisPtOnSurface, bool bLimit, Vector2d* const pParamOnSurface,double& minimalDistance,double disTolerance)const = 0;

        /// \brief  计算三维曲线到曲面的最小距离
        ///
        /// \param pSurface                            曲面
        /// \param pCurve3d                            三维曲线
        /// \param minimalDistance                     最小距离
        /// \param minimalDistancePointOnSurface       曲面上的最小距离点
        /// \param minimalDistancePointOnCurve         曲线上的最小距离点
        /// \param pParameterOnSurface                 最小距离点在曲面上的参数(指针输入为空时不输出)
        /// \param pParameterOnCurve                   最小距离点在曲线上的参数(指针输入为空时不输出)  
        /// \param distanceTolerance                   容差
        /// \return    true:成功； false:失败
        virtual bool Calculate(const ISurface* pSurface, const ICurve3d* pCurve3d, double& minimalDistance, Vector3d &minimalDistancePointOnSurface,
                               Vector3d &minimalDistancePointOnCurve, Vector2d* pParameterOnSurface, double* pParameterOnCurve, double distanceTolerance) const = 0;

        /// \brief  计算点到体的最小距离
        /// \param const IBody* pGmBody                体
        /// \param const Vector3d &queryPoint           三维点
        /// \param Vector3d &minDisPtOnBody            体上的最小距离点
        /// \param minimalDistance                          最小距离
        /// \param double disTolerance                  容差
        /// \return    true:成功； false:失败
        virtual bool Calculate(const IBody* pGmBody, const Vector3d &queryPoint, Vector3d &minDisPtOnBody, double& minimalDistance, double disTolerance)const = 0;

        /// \brief  计算体到体的最小距离
        /// \param pBody1                         体1
        /// \param pBody2                         体2
        /// \param minimalDistancePointOnBody1    体1上的最小距离点
        /// \param minimalDistancePointOnBody2    体2上的最小距离点
        /// \param minimalDistance                最小距离
        /// \param distanceTolerance              容差
        /// \return bool                          成功与否
        virtual bool Calculate(
            const IBody* pBody1, 
            const IBody* pBody2, 
            Vector3d &minDisPtOnBody1,
            Vector3d &minDisPtOnBody2, 
            double& minimalDistance, 
            double distanceTolerance
        ) const = 0;

        /// \brief  计算曲线到曲面的最小距离
        ///
        /// \param pSurface1                           曲面1
        /// \param pSurface2                           曲面2
        /// \param minimalDistance                     最短距离
        /// \param minimalDistancePointOnSurface1      曲面1上的最小距离点
        /// \param minimalDistancePointOnSurface2      曲线2上的最小距离点 
        /// \param distanceTolerance                   距离容差
        /// \return    true:成功； false:失败
        virtual bool Calculate(const ISurface* pSurface1, const ISurface* pSurface2, double& minimalDistance, Vector3d &minimalDistancePointOnSurface1, Vector3d &minimalDistancePointOnSurface2, double distanceTolerance) const = 0;

    };
}
